package com.eureka.server;

import com.netflix.discovery.shared.transport.EurekaHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DemoServerImpl implements DemoServer {


    @Autowired
    private DiscoveryClient discoveryClient;

//    @Autowired
//    private com.netflix.discovery.DiscoveryClient  eurekaClient;
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    public String sayHello(String str) {
        return "hello" + str;
    }


    public void doDiscoverServe(){
        List<String> services = discoveryClient.getServices();
        for (String service : services) {
            List<ServiceInstance> instances = discoveryClient.getInstances(service);
            System.out.println(instances);
        }
    }

    public void doDiscoverServe3(){
//        loadBalancerClient.choose("")
        // 创建一个Application实例，代表你的服务应用
//        Application app = new Application("MY-SERVICE");
//        // 手动添加实例信息，例如：
//        InstanceInfo instanceInfo = new InstanceInfo()
//        instanceInfo.setAppName("MY-SERVICE");
//        instanceInfo.setHostName("localhost"); // 或者使用InetAddress.getLocalHost().getHostName()获取主机名
//        instanceInfo.setIPAddr("127.0.0.1"); // 或者使用InetAddress.getLocalHost().getHostAddress()获取IP地址
//        instanceInfo.setPort(8080); // 你的服务端口号
//        instanceInfo.setDataCenterInfo(DataCenterInfo.Builder.newBuilder().setName("MyOwn").build()); // 数据中心信息，根据需要设置
//        app.addInstance(instanceInfo); // 将实例信息添加到应用中
//        eurekaClient.register(app); // 注册应用及其实例到Eureka服务器
//        eurekaClient.
    }
}
